package com.gwq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gwq.entity.SysRole;
import com.gwq.mapper.SysRoleMapper;
import com.gwq.service.SysRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gwq
 * @since 2022-06-07
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {

    @Override
    public List<SysRole> listRolesByUserId(String id) {
        List<SysRole> sysRoles =
                this.list(new QueryWrapper<SysRole>().inSql("id", "select role_id from sys_user_role where user_id = '" + id+"'"));
        return sysRoles;
    }

    @Override
    public SysRole getByCode(String code) {
        QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("code",code);
        return getOne(queryWrapper);
    }

    @Override
    public SysRole getByUserId(String userId) {
        return baseMapper.getByUserId(userId);
    }

    @Override
    public SysRole getUserType(String userId) {
        return baseMapper.getByUserType(userId);
    }
}
